<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>13_ES12-字符串replaceAll</title>
</head>
<body>

  <script>
    const message = 'Hello, world! Hello, Jack!';

    // 1. replaceAll() 方法用于替换字符串中所有匹配的子串
    const newMessage = message.replaceAll('Hello', 'Hi');
    console.log(newMessage); // Hi, world! Hi, Jack!

    // 2. replace() 方法用于替换字符串中第一个匹配的子串
    const newMessage2 = message.replace('Hello', 'Hi');
    console.log(newMessage2); // Hi, world! Hello, Jack!

  </script>
  
</body>
</html>